package com.wangxiang.crawler.utils;


import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class HttpClientUtil {
    public String http(String url) throws IOException {
        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpGet httpGet = new HttpGet(url);
        httpGet.setHeader("cookie","__jdu=1189059088; shshshfpa=57ab5630-2661-6c26-e9f3-36635300675f-1645939217; shshshfpb=vmMm9P6bzHXUO0NLHvtB4mg; qrsc=3; pinId=SWkSMUSA9yGoAbIPrdic7rV9-x-f3wj7; pin=jd_7a08f3cc70af8; unick=%E5%B0%8F%E7%8E%8B%E7%9A%84%E9%87%91%E5%BA%93; _tp=IsTep4cXjPHZuKJV31HnBYB3AL9OFofJ%2FMFBYmDGNZY%3D; _pst=jd_7a08f3cc70af8; areaId=24; unpl=JF8EAK9nNSttUElWAUsFGRAXTloBW1tbGB8Hb2UDVVRbQwMGTgRJEkJ7XlVdXhRKFR9vZxRUWVNLUQ4bCysSEXteXVdZDEsWC2tXVgQFDQ8VXURJQlZAFDNVCV9dSRZRZjJWBFtdT1xWSAYYRRMfDlAKDlhCR1FpMjVkXlh7VAQrAhsbGEpZXF9UAXsnBF9XNVxVXU9VASsDKxMgCQkIW1oJSBcFImcFXVVZT1wEEgsrEyBI; ipLoc-djd=24-2144-3909-21115; user-key=c422bee6-5635-4e39-8a03-ffd5deb742b2; __jda=122270672.1189059088.1645939216.1648193307.1648605030.42; __jdc=122270672; __jdv=122270672|direct|-|none|-|1648605029689; shshshfp=9b00bb630aa4a529959ffe6db12d8476; rkv=1.0; wlfstk_smdl=f3eobon2599471f6o6dl03hk8k43hobx; TrackID=1EuvyH2CO_xmfe1CzUvrgEoTASBQhYnRqch6r9K-1JcS-RMefHIMwUMH8NnUkdAVSY1mgKgBx28YX65thhva008DNBHsLd_g3DLNn3RJ7vpE; thor=A16B95BE4DBAA4EC31C00B5C80D4E2C6251F213BB6119E5D09C9F916DA621D7B06B9F6307E30484F5252FDD1B8377E1CB0ED9DA614F11D30659A46F8AF267DE6BC0E7AAA9CA0E5A3ACA06832E31B5DC11FA7F8287ECEC69335409A77896EF9D3429C3A0BC1BD42DE479B527B07191DD4058AE1FAAEC8381F071602C377E9695DD0BDBAAB0B65C7A1718D68821256E0CD06DF99D213D87B7F426CAE4BFA633C10; ceshi3.com=000; __jdb=122270672.7.1189059088|42.1648605030; shshshsID=903b4590c918861695f468e5334a5ee1_4_1648605084899; 3AB9D23F7A4B3C9B=IMSOVIGCVXMX77FJKBRRRV5D2P7CDLJQKJOUG63KRGZ5SFSX7O2VMHIEP4OURVT6GQRFRFPQY6RBP4MO2F7MBPKKGM");
        httpGet.setHeader("user-agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36");
        CloseableHttpResponse response = httpClient.execute(httpGet);
        String html = EntityUtils.toString(response.getEntity(), "utf8");
        if (html!=null){
            httpClient.close();
            response.close();
        }
        return html;
    }
}
